﻿@page "/Bas/SettlementAccount/Index"
@using nERP.ViewModel.Bas.SettlementAccountVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage
@attribute [ActionDescription("_Page.Bas.SettlementAccount.Index", "nERP.Bas.Controllers,SettlementAccount")]

<Table @ref="SettlementAccountListVMdataTable" TItem="nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View" OnQueryAsync="SettlementAccountListVMOnSearchSettlementAccount"
       IsStriped="true" IsBordered="true" ShowRefresh="false" ShowExtendEditButton="false" ShowExtendDeleteButton="false"
       ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true"
       AllowResizing="true" ShowDefaultButtons="false" IsPagination="true" AllowDragColumn="true" ShowColumnList="true" ShowSearch="true" SearchTooltip="" OnResetSearchAsync="OnResetSearchAsync"
       SearchPlaceholderText="@WtmBlazor.Localizer["Page.编号"]" SearchButtonText="" ResetSearchButtonText="" ShowAdvancedSearch="false">
    <TableColumns>
        <TableColumn @bind-Field="@context.SettlementAccount_Code" Text="@WtmBlazor.Localizer["Page.编号"]" />
        <TableColumn @bind-Field="@context.SettlementAccount_Name" Text="@WtmBlazor.Localizer["Page.名称"]" />
        <TableColumn @bind-Field="@context.SettlementAccount_BeginAmount" Text="@WtmBlazor.Localizer["Page.期初金额"]" FormatString="0.##" />
        <TableColumn @bind-Field="@context.SettlementAccount_NowAmount" Text="@WtmBlazor.Localizer["Page.当前余额"]" FormatString="0.##" />
        <TableColumn @bind-Field="@context.SettlementAccount_Remark" Text="@WtmBlazor.Localizer["_Admin.Remark"]" />
        <TableColumn @bind-Field="@context.SettlementAccount_CreateTime" Text="@WtmBlazor.Localizer["_Admin.CreateTime"]" FormatString="yyyy-MM-dd HH:mm:ss" />
        <TableColumn @bind-Field="@context.SettlementAccount_UpdateTime" Text="@WtmBlazor.Localizer["_Admin.UpdateTime"]" FormatString="yyyy-MM-dd HH:mm:ss" />
        <TableColumn @bind-Field="@context.SettlementAccount_CreateBy" Text="@WtmBlazor.Localizer["_Admin.CreateBy"]" />
        <TableColumn @bind-Field="@context.SettlementAccount_UpdateBy" Text="@WtmBlazor.Localizer["_Admin.UpdateBy"]" />
        <TableColumn @bind-Field="@context.SettlementAccount_IsValid" Text="@WtmBlazor.Localizer["_Admin.IsValid"]" />
    </TableColumns>

    <RowButtonTemplate>
        @if (IsAccessable("/api/Bas/SettlementAccount/Edit"))
        {
            <TableCellButton Size="Size.ExtraSmall" Icon="fa fa-pencil-square" Color="Color.Warning" Text="@WtmBlazor.Localizer["Sys.Edit"]" OnClick="()=>OnEditClick(context)" />
        }
        @if (IsAccessable("/api/Bas/SettlementAccount/{id}"))
        {
            <TableCellButton Size="Size.ExtraSmall" Icon="fa fa-info-circle" Color="Color.Info" Text="@WtmBlazor.Localizer["Page.详情"]" OnClick="()=>OnDetailsClick(context)" />
        }
        @if (IsAccessable("/api/Bas/SettlementAccount/BatchDelete"))
        {
            <PopConfirmButton OnConfirm="() => OnDeleteClick(context)" Size="Size.ExtraSmall" Icon="fa fa-trash" Color="Color.Danger" Text="@WtmBlazor.Localizer["Sys.Delete"]" Content="@WtmBlazor.Localizer["Sys.DeleteConfirm"]" CloseButtonText="@WtmBlazor.Localizer["Sys.Close"]" ConfirmButtonText="@WtmBlazor.Localizer["Sys.Delete"]"
                              ConfirmButtonColor="Color.Danger" />
        }
    </RowButtonTemplate>
    <TableToolbarTemplate>
        @if (IsAccessable("/api/Bas/SettlementAccount/Create"))
        {
            <TableToolbarButton TItem="nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View" Icon="fa fa-plus" Color="Color.Primary" Text="@WtmBlazor.Localizer["Sys.Create"]" OnClickCallback="(x)=>OnCreateClick()" />
        }
        @if (IsAccessable("/api/Bas/SettlementAccount/BatchDelete"))
        {
            <TableToolbarPopConfirmButton TItem="nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View"
                                          Icon="fa fa-trash" Color="Color.Danger" Text="@WtmBlazor.Localizer["Sys.Delete"]" Content="@WtmBlazor.Localizer["Sys.BatchDeleteConfirm"]" CloseButtonText="@WtmBlazor.Localizer["Sys.Close"]" ConfirmButtonText="@WtmBlazor.Localizer["Sys.BatchDelete"]"
                                          OnConfirm="@OnBatchDeleteClick" ConfirmButtonColor="Color.Danger" />
        }
        @if (IsAccessable("/api/Bas/SettlementAccount/BatchEdit"))
        {
            <TableToolbarButton TItem="nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View" Icon="fa fa-pencil-square" Color="Color.Primary" Text="@WtmBlazor.Localizer["Sys.BatchEdit"]" OnClickCallback="(x)=>OnBatchEditClick()" />
        }
        @if (IsAccessable("/api/Bas/SettlementAccount/Import"))
        {
            <TableToolbarButton TItem="nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View" Icon="fa fa-tasks" Color="Color.Primary" Text="@WtmBlazor.Localizer["Sys.Import"]" OnClickCallback="(x)=>OnImportClick()" />
        }
        @if (IsAccessable("/api/Bas/SettlementAccount/SettlementAccountExportExcel"))
        {
            <TableToolbarButton TItem="nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View" Icon="fa fa-arrow-circle-down" Color="Color.Primary" Text="@WtmBlazor.Localizer["Sys.Export"]" OnClickCallback="(x)=>OnExportClick()" IsAsync="true" />
        }
    </TableToolbarTemplate>

</Table>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private SettlementAccountListVM Model = new SettlementAccountListVM();
    private Table<nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View> SettlementAccountListVMdataTable;
    private Task OnResetSearchAsync(SettlementAccount_View item)
    {
        Model.Searcher = new SettlementAccountSearcher();
        item = new SettlementAccount_View();
        return Task.CompletedTask;
    }
    private async Task SettlementAccountListVMDoSearch()
    {
        await SettlementAccountListVMdataTable.QueryAsync();
    }
    private async Task<QueryData<nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View>> SettlementAccountListVMOnSearchSettlementAccount(QueryPageOptions opts)
    {
        Model.Searcher.Code = opts.SearchText;
        return await StartSearch<nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View>("/api/Bas/SettlementAccount/SearchSettlementAccount", Model.Searcher, opts);
    }
    private async Task OnCreateClick()
    {
        var id = SettlementAccountListVMdataTable.SelectedRows?.Select(x => x.ID.ToString())?.FirstOrDefault();
        if (await OpenDialog<Create>(@WtmBlazor.Localizer["Sys.Create"], x => x.id == (id ?? ""), isMax: false) == DialogResult.Yes)
        {
            await SettlementAccountListVMdataTable.QueryAsync();
        }
    }

    private async Task OnEditClick(nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View item)
    {
        if (await OpenDialog<Edit>(@WtmBlazor.Localizer["Sys.Edit"], x => x.id == item.ID.ToString(), isMax: false) == DialogResult.Yes)
        {
            await SettlementAccountListVMdataTable.QueryAsync();
        }
    }

    private async Task OnDetailsClick(nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View item)
    {
        if (await OpenDialog<Details>(@WtmBlazor.Localizer["Page.详情"], x => x.id == item.ID.ToString(), isMax: false) == DialogResult.Yes)
        {
            await SettlementAccountListVMdataTable.QueryAsync();
        }
    }

    private async Task OnDeleteClick(nERP.ViewModel.Bas.SettlementAccountVMs.SettlementAccount_View item)
    {
        await PostsData(new List<string> { item.ID.ToString() }, $"/api/Bas/SettlementAccount/batchdelete", (s) => "Sys.OprationSuccess");
        await SettlementAccountListVMdataTable.QueryAsync();
    }

    private async Task OnBatchDeleteClick()
    {
        if (SettlementAccountListVMdataTable.SelectedRows?.Any() == true)
        {
            await PostsData(SettlementAccountListVMdataTable.SelectedRows.Select(x => x.ID.ToString()).ToList(), $"/api/Bas/SettlementAccount/batchdelete", (s) => WtmBlazor.Localizer["Sys.BatchDeleteSuccess", s]);
            await SettlementAccountListVMdataTable.QueryAsync();
        }
        else
        {
            await WtmBlazor.Toast.Information(WtmBlazor.Localizer["Sys.Info"], WtmBlazor.Localizer["Sys.SelectOneRowMin"]);
        }
    }

    private async Task OnBatchEditClick()
    {
        if (SettlementAccountListVMdataTable.SelectedRows?.Any() == true)
        {
            if (await OpenDialog<BatchEdit>(WtmBlazor.Localizer["Sys.BatchEdit"], x => x.ids == SettlementAccountListVMdataTable.SelectedRows.Select(x => x.ID.ToString()).ToArray(), isMax: false) == DialogResult.Yes)
            {
                await SettlementAccountListVMdataTable.QueryAsync();
            }
        }
        else
        {
            await WtmBlazor.Toast.Information(WtmBlazor.Localizer["Sys.Info"], WtmBlazor.Localizer["Sys.SelectOneRowMin"]);
        }
    }

    private async Task OnImportClick()
    {
        var id = SettlementAccountListVMdataTable.SelectedRows?.Select(x => x.ID.ToString())?.FirstOrDefault();
        if (await OpenDialog<Import>(@WtmBlazor.Localizer["Sys.Import"], x => x.id == (id ?? ""), isMax: false) == DialogResult.Yes)
        {
            await SettlementAccountListVMdataTable.QueryAsync();
        }
    }

    private async Task OnExportClick()
    {
        if (SettlementAccountListVMdataTable.SelectedRows?.Any() == true)
        {
            await Download("/api/Bas/SettlementAccount/SettlementAccountExportExcelByIds", SettlementAccountListVMdataTable.SelectedRows.Select(x => x.ID.ToString()).ToList());
        }
        else
        {
            await Download("/api/Bas/SettlementAccount/SettlementAccountExportExcel", Model.Searcher);
        }
    }


    protected override async Task OnInitializedAsync()
    {



        await base.OnInitializedAsync();
    }
}
